package com.hexacta.hrs.web.struts.actions.staffing;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.Predicate;
import org.apache.commons.lang.StringUtils;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.interceptor.validation.SkipValidation;
import org.vectrics.common.util.DateUtil;
import org.vectrics.employee.Employee;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.recruiter.job.JobFunction;
import org.vectrics.recruiter.struts.tag.AvailabilityStatusColor;
import org.vectrics.user.Person;

import com.hexacta.hrs.domain.staffing.Project;
import com.hexacta.hrs.domain.staffing.Requirement;
import com.hexacta.hrs.domain.staffing.RequirementCalculatorHandler;
import com.hexacta.hrs.domain.staffing.RequirementResult;
import com.hexacta.hrs.domain.staffing.RequirementSkills;
import com.hexacta.hrs.domain.staffing.assignment.AvailabilityStatus;
import com.hexacta.hrs.domain.staffing.assignment.EmployeeAssignment;
import com.hexacta.hrs.domain.staffing.relationship.RequirementAssignmentRelationship;
import com.hexacta.hrs.securitygroups.PermissionNameConverter;
import com.hexacta.hrs.service.staffing.ProjectService;
import com.hexacta.hrs.services.crud.CrudService;
import com.hexacta.hrs.services.employee.EmployeeService;
import com.hexacta.hrs.services.feedbacks.FeedbackPeriodService;
import com.hexacta.hrs.services.feedbacks.FeedbackService;
import com.hexacta.hrs.services.staffing.EmployeeAssignmentService;
import com.hexacta.hrs.services.staffing.impl.EmployeeAssignmentDTO;
import com.hexacta.hrs.web.struts.actions.CrudAbstractAction;
import com.hexacta.hrs.web.struts.actions.security.PermissionChecker;
import com.opensymphony.xwork2.ActionContext;

import edu.emory.mathcs.backport.java.util.Collections;

/**
 * Action de Struts para {@link EmployeeAssignment}.
 * 
 * @author ncortinez
 * 
 */
public class RequirementAssignmentRelationshipAction extends CrudAbstractAction<Project> implements SessionAware {

    private static final long serialVersionUID = 3235542204841094722L;

    private static final String LIST = "listInitial";

    private static final String SELECT_PROYECT = "selectProject";

    private static final String DELETE = "delete";

    public static final String SUCCESS = "success";

    // private HttpServletRequest request;

    private PermissionChecker permissionChecker = new PermissionChecker();

    private PermissionNameConverter permissionNameConverter = new PermissionNameConverter();

    private ProjectService projectService;

    private EmployeeService employeeService;

    private EmployeeAssignmentService assignmentService;

    private FeedbackPeriodService feedbackPeriodService;

    private FeedbackService feedbackService;

    private String mappedRequest;
    
    private RequirementCalculatorHandler handler = new RequirementCalculatorHandler(); 
    
    // Campos del formulario.

    private Long requirementId;

    private String employeeId;

    private String selectedProjectId;

    private String selectedProjectName;

    private Date selectedStartDate;

    private Date selectedEndDate;

    private String searchString;

    private String actualPage = "1";

    private boolean showTentativesAssignments = true;

    private boolean showTentativesRequirements = true;

    private boolean showTentativesAvailableResources = true;

    private boolean showOnlyCurrentRequirements = true;

    private boolean showOnlyCurrentAssigned = true;

    private String selectedEmployeeId = "";

    private String selectedEmployeeName = "";

    private String[] selectedRoles;

    private Collection<String> selectedRolesBefore = new ArrayList<String>();

    private boolean showNoAsignado = false;

    private boolean showAsignadoCliente = true;

    private boolean showAddOnNotAvailable = true;

    private boolean showAddOnAvailable = true;

    private boolean showInterno = true;

    private boolean showTodos = false;

    private boolean showTimeOff = false;

    private boolean onlyElegibleProjectMember = false;

    private String resetAttributes;

    private String selectedProjectIdFilter;

    private String selectedProjectNameFilter;

    private Long selectedAssignmentId;
    
    private Double disponibilityPercentage;
    
    private Double seniorityPercentage;
	
    private Double skillsPercentage;
    
    private RequirementSkills requirementSkillsPopUp;

    // Respuestas del action
    private Project project;

    private List<EmployeeAssignmentDTO> employeeAssignmentList;

    private List<Requirement> requirementsList;

    private List<EmployeeAssignment> assignmentNoAddOnList;

    private List<EmployeeAssignment> assignmentAddOnList;

    private List<RequirementAssignmentRelationship> remainingRequirementsList;
    
    private List<RequirementResult> calculateResultList;

    private Map<String, Object> session;

    public List<Project> getProjectsList() {
        return getProjectService().findAll();
    }

    /* Actions */

    @SkipValidation
    public final String selectProject() {
        setMappedRequest(SELECT_PROYECT);
        return SUCCESS;
    }

    public final String listInitial() {
        if (StringUtils.equalsIgnoreCase(getResetAttributes(), "true")) {
            resetAttributesForm();
        }

        Project localProject = new Project();
        localProject.setName(getSelectedProjectName());

        if (StringUtils.isEmpty(getSelectedProjectName())
                || getProjectService().searchByCriteria(localProject).isEmpty()
                || StringUtils.isEmpty(getSelectedProjectId())) {
            addFieldError("invalidProject", "Requested project does not exist");
            setMappedRequest(ERROR);
        } else {
            listWithValidProject();
        }

        return SUCCESS;
    }

    private void listWithValidProject() {
        long id = Long.parseLong(getSelectedProjectId());
        setProject(getProjectService().searchById(id));

        List<RequirementAssignmentRelationship> list = new ArrayList<RequirementAssignmentRelationship>();
        list.addAll(getProject().getUnassignedRequirements(getShowTentativesRequirements()));
        if (showOnlyCurrentRequirements) {
            cropOldRequirements(list);
        }
        Collections.sort(list, new Comparator<RequirementAssignmentRelationship>() {
			@Override
			public int compare(RequirementAssignmentRelationship o1, RequirementAssignmentRelationship o2) {
				return o1.getRole().getCode().compareTo(o2.getRole().getCode());
			}
		});
        setRemainingRequirementsList(list);

        if (getSelectedStartDate() == null) {
            Date selectedStartDate = StaffingActionHelper.GenerarValorInicialDeStartDate();
            for (EmployeeAssignment employeeAssignment : getProject().getAssignments()) {
                if (selectedStartDate.after(employeeAssignment.getStartDate().getTime())) {
                    selectedStartDate = employeeAssignment.getStartDate().getTime();
                }

            }
            setSelectedStartDate(selectedStartDate);
        }

        if (getSelectedEndDate() == null) {
            Date selectedEndDate = StaffingActionHelper.GenerarValorInicialDeEndDate();
            for (EmployeeAssignment employeeAssignment : getProject().getAssignments()) {
                if (selectedEndDate.before(employeeAssignment.getEndDate().getTime())) {
                    selectedEndDate = employeeAssignment.getEndDate().getTime();
                }
            }
            setSelectedEndDate(selectedEndDate);
        }

        Employee employee;

        if (StringUtils.isEmpty(getSelectedEmployeeId()) && StringUtils.isEmpty(getSelectedEmployeeName())) {
            employee = null;
        } else if (StringUtils.isEmpty(getSelectedEmployeeId()) || StringUtils.isEmpty(getSelectedEmployeeName())) {
            employee = null;
            addFieldError("invalidEmployee", "Invalid selection for Employee filter.");
            setMappedRequest(ERROR);
        } else {
            employee = getEmployeeService().searchById(Long.parseLong(getSelectedEmployeeId()));
            if (employee != null && !getSelectedEmployeeName().trim().equals(employee.getPerson().getName().trim())) {
                addFieldError("invalidEmployee", "Invalid selection for Employee filter.");
                setMappedRequest(ERROR);
            }
        }

        if (StringUtils.isEmpty(getSelectedProjectIdFilter()) && StringUtils.isEmpty(getSelectedProjectNameFilter())) {
            // no hay error, pero tengo que diferenciar el caso
        } else if (StringUtils.isEmpty(getSelectedProjectIdFilter())
                || StringUtils.isEmpty(getSelectedProjectNameFilter())) {
            addFieldError("invalidProjectFilter", "Invalid selection for Project filter.");
            setMappedRequest(ERROR);
        } else {
            Project pr = projectService.searchById(Long.parseLong(getSelectedProjectIdFilter()));
            if (pr != null && !getSelectedProjectNameFilter().equals(pr.getName())) {
                addFieldError("invalidProjectFilter", "Invalid selection for Project filter.");
                setMappedRequest(ERROR);
            }
        }
        if (getSelectedEndDate().before(getSelectedStartDate())) {
            addFieldError("invalidDateFilter", "Invalid end date.");
            setMappedRequest(ERROR);
        }

        if (!ERROR.equals(getMappedRequest())) {
            setEmployeeAssignmentList(getAssignmentService().findAvailableResource(employee, getSelectedStartDate(),
                    getSelectedEndDate(), getShowTentativesAssignments(), getShowNoAsignado(),
                    getShowAsignadoCliente(), isShowAddOnAvailable(), isShowAddOnNotAvailable(), getShowInterno(),
                    getShowTimeOff(), getSelectedRoles(), getSelectedProjectId(), isOnlyElegibleProjectMember(),null));

            setMappedRequest(LIST);
            List<EmployeeAssignment> assignmentList = new ArrayList<EmployeeAssignment>();
            for (EmployeeAssignmentDTO assignmentDTO : getEmployeeAssignmentList()) {
                assignmentList.add(assignmentService.searchById(assignmentDTO.getAssignmentID()));
            }
            setAssignmentNoAddOnList(assignmentList);
        } else {
            setEmployeeAssignmentList(new ArrayList<EmployeeAssignmentDTO>());
        }

        if (getShowOnlyCurrentAssigned()) {
            CollectionUtils.filter(getAssignmentNoAddOnList(), new Predicate() {
                @Override
                public boolean evaluate(final Object object) {
                    EmployeeAssignment assignment = (EmployeeAssignment) object;
                    return assignment.getEndDate().compareTo(Calendar.getInstance()) >= 0;
                }
            });

            CollectionUtils.filter(getEmployeeAssignmentList(), new Predicate() {
                @Override
                public boolean evaluate(final Object object) {
                    EmployeeAssignmentDTO assignment = (EmployeeAssignmentDTO) object;
                    return assignment.getTo().compareTo(Calendar.getInstance()) >= 0;
                }
            });

        }
        // Cargamos en la lista selectedRolesBoefore, las keys de los roles
        // anteriormente selecionados, para que cuando se cargue de nuevo la
        // pagina no se pierdan
        loadSelectedRolesBefore();

        saveSearchCriteria();
    }

    /**
     * @param list2
     */
    private void cropOldRequirements(final List<RequirementAssignmentRelationship> list) {
        Iterator<RequirementAssignmentRelationship> reqIter = list.iterator();
        Calendar newStart = Calendar.getInstance();
        newStart.set(Calendar.HOUR, 0);
        newStart.set(Calendar.MINUTE, 0);
        newStart.set(Calendar.SECOND, 0);

        while (reqIter.hasNext()) {
            RequirementAssignmentRelationship req = reqIter.next();
            if (req.getEndDate().before(newStart)) {
                reqIter.remove();
            } else {
                if (req.getStartDate().before(newStart)) {
                    req.setStartDate(newStart);
                }
            }
        }
    }

    public String closeAssignment() {
        EmployeeAssignment assignment = assignmentService.searchById(getSelectedAssignmentId());
        if (assignment.getEndDate().after(Calendar.getInstance())
                && assignment.getStartDate().before(Calendar.getInstance())) {
            assignment.setEndDate(Calendar.getInstance());
            assignment.getEndDate().set(Calendar.HOUR, 0);
            assignment.getEndDate().set(Calendar.MINUTE, 0);
            assignment.getEndDate().set(Calendar.SECOND, 0);
            assignment.getEndDate().set(Calendar.MILLISECOND, 0);
            assignmentService.save(assignment);
        } else {
            addFieldError("projectsList", "You can only close active assignments");
        }
        listInitial();
        loadSelectedRolesBefore();
        saveSearchCriteria();

        return SUCCESS;
    }

    public String deleteAssignment() {
        Person person = CoreServiceLocator.getUserAuthService().getAuthorizedPerson(getSession());

        EmployeeAssignment assignment = assignmentService.searchById(getSelectedAssignmentId());
        assignmentService.delete(assignment);
        feedbackService.deleteFeedbackForAssignment(assignment, person);
        listInitial();
        loadSelectedRolesBefore();
        saveSearchCriteria();

        return SUCCESS;
    }

    /**
     * @return
     */
    private String getMappedRequest() {
        String ret = "";
        if (!StringUtils.isEmpty(mappedRequest)) {
            String[] request = mappedRequest.split("_");
            ret = request[request.length - 1];
        }
        return ret;
    }

    private void saveSearchCriteria() {
        AssignmentFilters filters = new AssignmentFilters();

        filters.setActualPage(getActualPage());
        filters.setGanttEndDate(getSelectedEndDate());
        filters.setGanttStartDate(getSelectedStartDate());
        filters.setSelectedEmployeeId(getSelectedEmployeeId());
        filters.setSelectedEmployeeName(getSelectedEmployeeName());
        filters.setSelectedProjectIdFilter(getSelectedProjectIdFilter());
        filters.setSelectedProjectNameFilter(getSelectedProjectNameFilter());
        filters.setSelectedProjectId(getSelectedProjectId());
        filters.setSelectedProjectName(getSelectedProjectName());
        filters.setSelectedRoles(getSelectedRoles());
        filters.setSelectedRolesBefore(getSelectedRolesBefore());
        filters.setShowAddOnAvailable(isShowAddOnAvailable());
        filters.setShowAddOnNotAvailable(isShowAddOnNotAvailable());
        filters.setShowAsignadoCliente(getShowAsignadoCliente());
        filters.setShowInterno(getShowInterno());
        filters.setShowNoAsignado(getShowNoAsignado());
        filters.setShowTentativesAvailableResources(getShowTentativesAvailableResources());
        filters.setShowTodos(getShowTodos());
        filters.setElegibleProjectMember(isOnlyElegibleProjectMember());
        filters.setShowOnlyCurrentAssignments(isShowOnlyCurrentRequirements());
        filters.setSelectedRequirementId(getRequirementId());
        
        getSession().put("assignmentFilters", filters);
        getSession().put("return_to_search_action",
                "RequirementAssignmentRelationshipAction_listUsingFilterAttributesFromSession");
    }

    public String listUsingFilterAttributesFromSession() {

        if (getSession().containsKey("assignmentFilters")) {
            AssignmentFilters filters = (AssignmentFilters) getSession().get("assignmentFilters");

            setActualPage(filters.getActualPage());
            setSelectedEndDate(filters.getGanttEndDate());
            setSelectedStartDate(filters.getGanttStartDate());
            setSelectedEmployeeId(filters.getSelectedEmployeeId());
            setSelectedEmployeeName(filters.getSelectedEmployeeName());
            setSelectedProjectIdFilter(filters.getSelectedProjectIdFilter());
            setSelectedProjectNameFilter(filters.getSelectedProjectNameFilter());
            setSelectedProjectId(filters.getSelectedProjectId());
            setSelectedProjectName(filters.getSelectedProjectName());
            setSelectedRoles(filters.getSelectedRoles());
            setSelectedRolesBefore(filters.getSelectedRolesBefore());
            setShowAddOnNotAvailable(filters.isShowAddOnNotAvailable());
            setShowAddOnNotAvailable(filters.isShowAddOnNotAvailable());
            setShowAsignadoCliente(filters.getShowAsignadoCliente());
            setShowInterno(filters.getShowInterno());
            setShowNoAsignado(filters.getShowNoAsignado());
            setShowTentativesAvailableResources(filters.getShowTentativesAvailableResources());
            setShowTodos(filters.getShowTodos());
            setOnlyElegibleProjectMember(filters.getElegibleProjectMember());
            setShowOnlyCurrentRequirements(filters.isShowOnlyCurrentAssignments());
            setRequirementId(getRequirementId());
            
            getSession().remove("assignmentFilters");
        }

        return listInitial();
    }

    private void resetAttributesForm() {
        setShowTentativesAvailableResources(true);
        setShowNoAsignado(true);
        setShowAsignadoCliente(false);
        setShowAddOnAvailable(true);
        setShowAddOnNotAvailable(true);
        setShowInterno(false);
        setShowTimeOff(false);
        setOnlyElegibleProjectMember(true);

        setSelectedStartDate(StaffingActionHelper.GenerarValorInicialDeStartDate());
        setSelectedEndDate(StaffingActionHelper.GenerarValorInicialDeEndDate());

        setSelectedEmployeeId("");
        setSelectedEmployeeName("");

        setSelectedProjectIdFilter("");
        setSelectedProjectNameFilter("");

        selectedRolesBefore.clear();
        setSelectedRoles(new String[] {});

        setResetAttributes("false");
    }

    private void loadSelectedRolesBefore() {
        if (selectedRoles != null) {
            CollectionUtils.addAll(selectedRolesBefore, selectedRoles);
        }
    }
    
    public String calculateSetList(){
    	setCalculateResultList(calculate());
    	return listUsingFilterAttributesFromSession();
    }
    
    @SuppressWarnings("static-access")
	public List<RequirementResult> calculate(){
		if (getSelectedProjectId() != null) {
			Project reqProject = getProjectService().searchById(Long.parseLong(getSelectedProjectId()));
			Requirement requirement = reqProject.findRequirement(getRequirementId());
			List<Employee> employees = this.projectService.findRequirementResults(requirement);
			
			Map<Employee, Calendar> map = new HashMap<Employee, Calendar>();
			for (Employee employee : employees) {
				Calendar availability = assignmentService.availabilityInMonths(employee);
				availability.add(Calendar.DATE, +1);
				Integer months = resultBetweenDates(requirement.getStartDate(), availability);
				if(months <3){
					map.put(employee, availability);
				}
			}
			
			handler.getCalculator().setDisponibilityPercentage(getDisponibilityPercentage()/100);
			handler.getCalculator().setSeniorityPercentage(getSeniorityPercentage()/100);
			handler.getCalculator().setSkillsPercentage(getSkillsPercentage()/100);
			
			return handler.calculate(requirement, map);
		}
		return null;
    }
    
    public Integer resultBetweenDates(final Calendar begin,final  Calendar end){
    	Calendar lastAssignment = Calendar.getInstance();
    	lastAssignment.setTime(end.getTime());
    	Calendar start = Calendar.getInstance();
    	start.setTime(begin.getTime());
    	if (lastAssignment.before(start)) {
			return 0;
		}else{
			lastAssignment.add(Calendar.MONTH, +1);
			if (lastAssignment.before(start) ) {
				return 1;
			}else{
				lastAssignment.add(Calendar.MONTH, +1);
				if (lastAssignment.before(start) ) {
					return 1;
				}
				else return 3;
			}
			
		}
    }
    
    public String closeRequirement() {

        if (getSelectedProjectId() != null) {
            Project reqProject = getProjectService().searchById(Long.parseLong(getSelectedProjectId()));
            Requirement requirement = reqProject.findRequirement(getRequirementId());

            Calendar today = new GregorianCalendar();
            if (requirement.getStartDate().before(today) && requirement.getEndDate().after(today)) {
                requirement.setEndDate(today);
                requirement.getEndDate().set(Calendar.HOUR, 0);
                requirement.getEndDate().set(Calendar.MINUTE, 0);
                requirement.getEndDate().set(Calendar.SECOND, 0);
                requirement.getEndDate().set(Calendar.MILLISECOND, 0);

                getProjectService().save(reqProject);
            } else {
                addFieldError("projectsList", "You can only close active requirements");
            }

        }

        return listUsingFilterAttributesFromSession();
    }

    public String deleteRequirement() {

        if (getSelectedProjectId() != null) {
            Project reqProject = getProjectService().searchById(Long.parseLong(getSelectedProjectId()));
            Requirement requirement = reqProject.findRequirement(getRequirementId());

            reqProject.removeRequirement(requirement);

            getProjectService().save(reqProject);
        }

        return listUsingFilterAttributesFromSession();
    }
    
    public String selectedRequirementResult(){
    	calculateSetList();
    	return listUsingFilterAttributesFromSession();
    }
    
    public Requirement getSelectedRequirement(){
		if (getSelectedProjectId() != null) {
			Project reqProject = getProjectService().searchById(Long.parseLong(getSelectedProjectId()));
			Requirement requirement = reqProject.findRequirement(getRequirementId());
			return requirement;
		}
		return null;
    }
    
    public String getStartDateAsString() {
        return DateUtil.getFechaFormateada(getSelectedStartDate());
    }

    public String getEndDateAsString() {
        return DateUtil.getFechaFormateada(getSelectedEndDate());
    }

    public List<Employee> getEmployeeList() {
        return (List<Employee>) getEmployeeService().getAllCurrentEmployees();
    }

    public List<JobFunction> getRoles() {
        return RecruitServiceLocator.getJobProvider().findAllJobFunctions();
    }

    /* Metodos de seguridad y struts */

    @Override
    public void setPermissionNameConverter(final PermissionNameConverter permissionNameConverter) {
        this.permissionNameConverter = permissionNameConverter;
    }

    @Override
    public PermissionNameConverter getPermissionNameConverter() {
        return permissionNameConverter;
    }

    @Override
    public String getActionMethod() {
        return mappedRequest;
    }

    // when invalid, the request parameter will restore command action
    @Override
    public void setActionMethod(final String method) {
        mappedRequest = method;
    }

    // this prepares command for button on initial screen write
    @Override
    public void setMappedRequest(final String actionMethod) {
        mappedRequest = getClass().getSimpleName() + "_" + actionMethod;
    }

    /** @return {@link Person} logueado */
    @Override
    protected Person getAuthPerson() {
        Person person = CoreServiceLocator.getUserAuthService().getAuthorizedPerson(getRequest().getSession());
        return person;
    }

    @Override
    public boolean hasPermission(final String permission) {
        return getPermissionChecker().hasPermission(permission, getRequest().getSession());
    }

    @Override
    public void setPermissionChecker(final PermissionChecker permissionChecker) {
        this.permissionChecker = permissionChecker;
    }

    @Override
    public PermissionChecker getPermissionChecker() {
        return permissionChecker;
    }

    /* Getters y Setters */

    public String getSelectedProjectId() {
        return selectedProjectId;
    }

    public void setSelectedProjectId(final String selectedProjectId) {
        this.selectedProjectId = selectedProjectId;
    }

    public String getSelectedProjectName() {
        return selectedProjectName;
    }

    public void setSelectedProjectName(final String selectedProjectName) {
        this.selectedProjectName = selectedProjectName;
    }

    public void setProjectService(final ProjectService projectService) {
        this.projectService = projectService;
    }

    public ProjectService getProjectService() {
        return projectService;
    }

    @Override
    public String getDestination() {
        return getActionMethod();
    }

    public void setProject(final Project project) {
        this.project = project;
    }

    public Project getProject() {
        return project;
    }

    public void setSelectedStartDate(final Date selectedStartDate) {
        this.selectedStartDate = selectedStartDate;
    }

    public Date getSelectedStartDate() {
        return selectedStartDate;
    }

    public void setSelectedEndDate(final Date selectedEndDate) {
        this.selectedEndDate = selectedEndDate;
    }

    public Date getSelectedEndDate() {
        return selectedEndDate;
    }

    public void setSearchString(final String searchString) {
        this.searchString = searchString;
    }

    public String getSearchString() {
        return searchString;
    }

    public void setEmployeeAssignmentList(final List<EmployeeAssignmentDTO> employeeAssignmentList) {
        this.employeeAssignmentList = employeeAssignmentList;
    }

    public List<EmployeeAssignmentDTO> getEmployeeAssignmentList() {
        return employeeAssignmentList;
    }

    public void setAssignmentService(final EmployeeAssignmentService assignmentService) {
        this.assignmentService = assignmentService;
    }

    public EmployeeAssignmentService getAssignmentService() {
        return assignmentService;
    }

    public void setShowTentativesAvailableResources(final boolean showTentatives) {
        showTentativesAvailableResources = showTentatives;
    }

    public boolean getShowTentativesAvailableResources() {
        return showTentativesAvailableResources;
    }

    public boolean getShowNoAsignado() {
        return showNoAsignado;
    }

    public void setShowNoAsignado(final boolean showNoAsignado) {
        this.showNoAsignado = showNoAsignado;
    }

    public boolean getShowAsignadoCliente() {
        return showAsignadoCliente;
    }

    public void setShowAsignadoCliente(final boolean showAsignadoCliente) {
        this.showAsignadoCliente = showAsignadoCliente;
    }

    public boolean getShowInterno() {
        return showInterno;
    }

    public void setShowInterno(final boolean showInterno) {
        this.showInterno = showInterno;
    }

    public boolean getShowTodos() {
        return showTodos;
    }

    public void setShowTodos(final boolean showTodos) {
        this.showTodos = showTodos;
    }

    public String getNoAsignadoColor() {
        return AvailabilityStatusColor.getColor(AvailabilityStatus.NoAsignado);
    }

    public String getTimeOffColor() {
        return AvailabilityStatusColor.getColor(AvailabilityStatus.TimeOff);
    }

    public String getAsignadoClienteColor() {
        return AvailabilityStatusColor.getColor(AvailabilityStatus.AsignadoCliente);
    }

    public String getAddOnAvailableColor() {
        return AvailabilityStatusColor.getColor(AvailabilityStatus.AddOnAvailable);
    }

    public String getAddOnNotAvailableColor() {
        return AvailabilityStatusColor.getColor(AvailabilityStatus.AddOnNotAvailable);
    }

    public String getInternoColor() {
        return AvailabilityStatusColor.getColor(AvailabilityStatus.Interno);
    }

    public String getAreaColor() {
        return AvailabilityStatusColor.getColor(AvailabilityStatus.Area);
    }

    public void setActualPage(final String actualPage) {
        this.actualPage = actualPage;
    }

    public String getActualPage() {
        return actualPage;
    }

    public void setEmployeeService(final EmployeeService employeeService) {
        this.employeeService = employeeService;
    }

    public EmployeeService getEmployeeService() {
        return employeeService;
    }

    public void setSelectedEmployeeId(final String selectedEmployeeId) {
        this.selectedEmployeeId = selectedEmployeeId;
    }

    public String getSelectedEmployeeId() {
        return selectedEmployeeId;
    }

    public void setSelectedEmployeeName(final String selectedEmployeeName) {
        this.selectedEmployeeName = selectedEmployeeName;
    }

    public String getSelectedEmployeeName() {
        return selectedEmployeeName;
    }

    public void setSelectedRoles(final String[] selectedRoles) {
        this.selectedRoles = selectedRoles;
    }

    public String[] getSelectedRoles() {
        return selectedRoles;
    }

    public Collection<String> getSelectedRolesBefore() {
        return selectedRolesBefore;
    }

    public void setSelectedRolesBefore(final Collection<String> selectedRolesBefore) {
        this.selectedRolesBefore = selectedRolesBefore;
    }

    public void setRequirementsList(final List<Requirement> requirementsList) {
        this.requirementsList = requirementsList;
    }

    public List<Requirement> getRequirementsList() {
        return requirementsList;
    }

    public void setAssignmentNoAddOnList(final List<EmployeeAssignment> assignmentsList) {
        assignmentNoAddOnList = assignmentsList;
    }

    public List<EmployeeAssignment> getAssignmentNoAddOnList() {
        return assignmentNoAddOnList;
    }

    public void setRemainingRequirementsList(final List<RequirementAssignmentRelationship> remainingRequirementsList) {
        this.remainingRequirementsList = remainingRequirementsList;
    }

    public List<RequirementAssignmentRelationship> getRemainingRequirementsList() {
        return remainingRequirementsList;
    }
    
    public List<RequirementResult> getCalculateResultList() {
		return calculate();
	}

	public void setCalculateResultList(List<RequirementResult> calculateResultList) {
		this.calculateResultList = calculateResultList;
	}

	public void setShowTentativesAssignments(final boolean showTentativesAssignments) {
        this.showTentativesAssignments = showTentativesAssignments;
    }

    public boolean getShowTentativesAssignments() {
        return showTentativesAssignments;
    }

    public void setShowTentativesRequirements(final boolean showTentativesRequirements) {
        this.showTentativesRequirements = showTentativesRequirements;
    }

    public boolean getShowTentativesRequirements() {
        return showTentativesRequirements;
    }

    public void setShowOnlyCurrentAssigned(final boolean showOnlyCurrent) {
        showOnlyCurrentAssigned = showOnlyCurrent;
    }

    public boolean getShowOnlyCurrentAssigned() {
        return showOnlyCurrentAssigned;
    }

    public void setAssignmentAddOnList(final List<EmployeeAssignment> assignmentAddOnList) {
        this.assignmentAddOnList = assignmentAddOnList;
    }

    public List<EmployeeAssignment> getAssignmentAddOnList() {
        return assignmentAddOnList;
    }

    public String getSelectedProjectNameFilter() {
        return selectedProjectNameFilter;
    }

    public void setSelectedProjectNameFilter(final String selectedProjectNameFilter) {
        this.selectedProjectNameFilter = selectedProjectNameFilter;
    }

    public String getSelectedProjectIdFilter() {
        return selectedProjectIdFilter;
    }

    public void setSelectedProjectIdFilter(final String selectedProjectIdFilter) {
        this.selectedProjectIdFilter = selectedProjectIdFilter;
    }

    public String getEmployeeId() {
        return employeeId;
    }

    public void setEmployeeId(final String employeeId) {
        this.employeeId = employeeId;
    }

    public String getResetAttributes() {
        return resetAttributes;
    }

    public void setResetAttributes(final String resetAttributes) {
        this.resetAttributes = resetAttributes;
    }

    public Map getSession() {
        return ActionContext.getContext().getSession();
    }

    public boolean getShowTimeOff() {
        return showTimeOff;
    }

    public void setShowTimeOff(final boolean showTimeOff) {
        this.showTimeOff = showTimeOff;
    }

    /**
     * @param showAddOnNotAvailable
     *            the showAddOnNotAvailable to set
     */
    public void setShowAddOnNotAvailable(final boolean showAddOnNotAvailable) {
        this.showAddOnNotAvailable = showAddOnNotAvailable;
    }

    /**
     * @return the showAddOnNotAvailable
     */
    public boolean isShowAddOnNotAvailable() {
        return showAddOnNotAvailable;
    }

    /**
     * @param showAddOnAvailable
     *            the showAddOnAvailable to set
     */
    public void setShowAddOnAvailable(final boolean showAddOnAvailable) {
        this.showAddOnAvailable = showAddOnAvailable;
    }

    /**
     * @return the showAddOnAvailable
     */
    public boolean isShowAddOnAvailable() {
        return showAddOnAvailable;
    }

    public void setOnlyElegibleProjectMember(final boolean elegibleProjectMember) {
        onlyElegibleProjectMember = elegibleProjectMember;
    }

    public boolean isOnlyElegibleProjectMember() {
        return onlyElegibleProjectMember;
    }

    public Long getSelectedAssignmentId() {
        return selectedAssignmentId;
    }

    public void setSelectedAssignmentId(final Long selectedAssignmentId) {
        this.selectedAssignmentId = selectedAssignmentId;
    }
    
	public Double getDisponibilityPercentage() {
		if(disponibilityPercentage==null){
			return handler.getCalculator().getDisponibilityPercentage()*100;
		}else{
			return disponibilityPercentage;
		}
	}

	public void setDisponibilityPercentage(Double disponibilityPercentage) {
		this.disponibilityPercentage = disponibilityPercentage;
	}

	public Double getSeniorityPercentage() {
		if(seniorityPercentage==null){
			return handler.getCalculator().getSeniorityPercentage()*100;
		}else{
			return seniorityPercentage;
		}
	}

	public void setSeniorityPercentage(Double seniorityPercentage) {
		this.seniorityPercentage = seniorityPercentage;
	}

	public Double getSkillsPercentage() {
		if(skillsPercentage==null){
			return handler.getCalculator().getSkillsPercentage()*100;
		}else{
			return skillsPercentage;
		}
	}

	public void setSkillsPercentage(Double skillsPercentage) {
		this.skillsPercentage = skillsPercentage;
	}

	public RequirementSkills getRequirementSkillsPopUp() {
		return requirementSkillsPopUp;
	}

	public void setRequirementSkillsPopUp(RequirementSkills requirementSkillsPopUp) {
		this.requirementSkillsPopUp = requirementSkillsPopUp;
	}

	/**
     * @return the requirementId
     */
    public Long getRequirementId() {
        return requirementId;
    }

    /**
     * @param requirementId
     *            the requirementId to set
     */
    public void setRequirementId(final Long requirementId) {
        this.requirementId = requirementId;
    }

    public boolean isFromPopUp() {
        return true;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.hexacta.hrs.web.struts.actions.CrudAbstractAction#getCrudService()
     */
    @Override
    protected CrudService<Project> getCrudService() {
        return projectService;
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * org.apache.struts2.interceptor.SessionAware#setSession(java.util.Map)
     */
    @Override
    public void setSession(final Map<String, Object> session) {
        this.session = session;
    }

    /**
     * @param showOnlyCurrentRequirements
     *            the showOnlyCurrentRequirements to set
     */
    public void setShowOnlyCurrentRequirements(final boolean showOnlyCurrentRequirements) {
        this.showOnlyCurrentRequirements = showOnlyCurrentRequirements;
    }

    /**
     * @return the showOnlyCurrentRequirements
     */
    public boolean isShowOnlyCurrentRequirements() {
        return showOnlyCurrentRequirements;
    }

    /**
     * @return the feedbackPeriodService
     */
    public FeedbackPeriodService getFeedbackPeriodService() {
        return feedbackPeriodService;
    }

    /**
     * @param feedbackPeriodService
     *            the feedbackPeriodService to set
     */
    public void setFeedbackPeriodService(final FeedbackPeriodService feedbackPeriodService) {
        this.feedbackPeriodService = feedbackPeriodService;
    }

    /**
     * @return the feedbackService
     */
    public FeedbackService getFeedbackService() {
        return feedbackService;
    }

    /**
     * @param feedbackService
     *            the feedbackService to set
     */
    public void setFeedbackService(final FeedbackService feedbackService) {
        this.feedbackService = feedbackService;
    }

}
